﻿using Common.Prism.Apps;
using NxChatQQ.Models;
using NxChatQQ.Models.Events;
using Prism.Commands;
using System.Windows.Input;

namespace NxChatQQ.ViewModels.Layouts
{
    public class FriendInfoLayoutViewModel : BaseViewModel
    {


        public ICommand TxtSendCommand { get; set; }



        private Friend _mFriend;
        public Friend mFriend
        {
            get { return _mFriend; }
            set { SetProperty(ref _mFriend, value); }
        }


        private string _NameTitle = "";
        public string NameTitle
        {
            get { return _NameTitle; }
            set { SetProperty(ref _NameTitle, value); }
        }


        private bool _IsEmpty = true;
        public bool IsEmpty
        {
            get { return _IsEmpty; }
            set { SetProperty(ref _IsEmpty, value); }
        }


        public FriendInfoLayoutViewModel()
        {

            // 订阅事件
            GetEvent<UpdateFriendInfoEvent>().Subscribe(UpdateChatMethod);


            TxtSendCommand = new DelegateCommand(FriendSendClick);
        }

        private void FriendSendClick()
        {
            GetEvent<UpdateChatEvent>().Publish(mFriend);
            GetEvent<UpdateNavEvent>().Publish(0);
        }

        private void UpdateChatMethod(Friend friend)
        {
            this.mFriend = friend;
            IsEmpty = friend == null;

            if (!IsEmpty)
            {
                NameTitle = friend.Name;
            }
        }


    }
}